#include "stdio.h"
int search(char a, int x1, int x2, int y1, int y2);
char data[19][19];
main(){
	int i,j,n1,x1,x2,y1,y2;
	char ch,t;
	for(i=0;i<19;i++){
		for(j=0;j<19;j++){
			data[i][j]=' ';
		}
	}
	for(ch='j',i=0;i<19;i++){
		for(t=ch,j=0;t<='j';j++,t++){
			data[i][9-j]=data[i][9+j]=t;
		}
		if(i<9)
			ch--;
		else
			ch++;
	}
	scanf("%d",&n1);
	for(i=1;i<=n1;i++){
		int m,n,t,t1,t2,t3,t4;
		unsigned int s=0;
		ch=getchar();
		scanf("%c",&ch);
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		m=((x2-1)/19)-((x1-1)/19)-1;
		n=((y2-1)/19)-((y1-1)/19)-1;
		if(m==-1){
			if(n==-1){
				s+=search(ch,(x1-1)%19,(y1-1)%19,(x2-1)%19,(y2-1)%19);
			}
			else{
				s+=search(ch,(x1-1)%19,(y1-1)%19,(x2-1)%19,18);
				s+=search(ch,(x1-1)%19,0,(x2-1)%19,(y2-1)%19);
				if(n>0){
					s+=n*search(ch,(x1-1)%19,0,(x2-1)%19,18);
				}
			}
		}
		else if(n==-1){
			s+=search(ch,(x1-1)%19,(y1-1)%19,18,(y2-1)%19);
			s+=search(ch,0,(y1-1)%19,(x2-1)%19,(y2-1)%19);
			if(m>0){
				s+=m*search(ch,0,(y1-1)%19,18,(y2-1)%19);
			}
		}
		else{
			s+=search(ch,(x1-1)%19,(y1-1)%19,18,18);
			s+=search(ch,(x1-1)%19,0,18,(y2-1)%19);
			s+=search(ch,0,(y1-1)%19,(x2-1)%19,18);
			s+=search(ch,0,0,(x2-1)%19,(y2-1)%19);
			if(m>0){
				t1=search(ch,0,(y1-1)%19,18,18);
				t4=search(ch,0,0,18,(y2-1)%19);
				s+=m*(t1+t4);
			}
			if(n>0){
				t2=search(ch,(x1-1)%19,0,18,18);
				t3=search(ch,0,0,(x2-1)%19,18);
				s+=n*(t2+t3);
			}
			if(m>0&&n>0){
				t=search(ch,0,0,18,18);
				s+=n*m*t;
		}
		}
		printf("Case %d: %d\n",i,s);
	}
}
int search(char c, int x1, int y1, int x2, int y2){
	int i,j,count=0;
	for(j=y1;j<=y2;j++){
		for(i=x1;i<=x2;i++){
			if(data[i][j]==c)
				count++;
		}
	}
	return count;
}